//mysqlserver.js
const express=require('express')
const app=express()
//引入mysql的依赖模块
const mysql=require('mysql')
//创建myqsl的连接池
const db=mysql.createPool({
    host:'localhost',
    port:3306,
    user:'root',
    password:'123456',
    database:'shopdb'
})
//获取t_goods表中的数据
app.get('/list',(req,res)=>{
    //新增
    // let sql="insert into t_goods values (5,'Huawei','手机','./images/03.png',3299)"
//删除
// let sql="delete from t_goods where id=5"
//更改
//let sql="update t_goods set price =price * 0.9 where id=4"
//查询
    let sql='select * from t_goods '
    //调用query方法访问数据库，[]为请求的参数，result是数据库的响应数据
    db.query(sql,[],(err,result)=>{
        res.send(result)
    })
})
app.listen(3001,()=>{
    console.log('server is running at port 3001');
})